package farkle;
/*
 * FarkleApp.java
 */

import org.jdesktop.application.Application;
import javax.swing.*;
import java.lang.*;

/**
 * The main class of the application.
 */
public class FarkleApp extends JApplet {
    
    
    
     // Main method launching the application.*/
     
    public static void main(String[] args) {
        FarkleFrame farkle = new FarkleFrame();
        farkle.setVisible(true);
        
        

        int[] dice = new int[6];
        for(int a = 0; a < dice.length; a++)
            dice[a] = FarkleFrame.Dice[a].getValue();
        
     }

    

    public static int score(int[] heldDice) {
        
        int ones = 0, twos = 0, threes = 0, fours = 0, fives = 0, sixes = 0;
        int[] counts = new int[6];
        int score = 0;
        int x = 0;
        int dieFace;
        boolean[] straight = {false, false, false, false, false, false};
        int straights = 0;
        boolean[] twoOfAKind = {false, false, false, false, false, false};
        int doubles = 0;
        int triples = 0;

        for(int i = 0; i < heldDice.length; i++) 
        {
            switch (heldDice[i]) {
                case 1:
                    ones += 1;
                    break;
                case 2:
                    twos += 1;
                    break;
                case 3:
                    threes += 1;
                    break;
                case 4:
                    fours += 1;
                    break;
                case 5:
                    fives += 1;
                    break;
                case 6:
                    sixes += 1;
                    break;
            }
        }
        counts[0] = ones;
        counts[1] = twos;
        counts[2] = threes;
        counts[3] = fours;
        counts[4] = fives;
        counts[5] = sixes;
    
        
        

        for (x = 0; x < counts.length; x++) {
            dieFace = x + 1;

            switch (counts[x]) {
                case 1:
                    switch (dieFace) {
                        case 1:
                            score += 100;
                            straight[0] = true;
                            break;
                        case 2:
                            straight[1] = true;
                            break;
                        case 3:
                            straight[2] = true;
                            break;
                        case 4:
                            straight[3] = true;
                            break;
                        case 5:
                            score += 50;
                            straight[4] = true;
                            break;
                        case 6:
                            straight[5] = true;
                            break;
                    }
                    break;
                case 2:
                    switch (dieFace) {
                        case 1:
                            score += 200;
                            twoOfAKind[0] = true;
                            break;
                        case 2:
                            twoOfAKind[1] = true;
                            break;
                        case 3:
                            twoOfAKind[2] = true;
                            break;
                        case 4:
                            twoOfAKind[3] = true;
                            break;
                        case 5:
                            score += 100;
                            twoOfAKind[4] = true;
                            break;
                        case 6:
                            twoOfAKind[5] = true;
                            break;
                    }
                    break;

                case 3:
                    switch (dieFace) {
                        case 1:
                            score += 1000;                            
                            break;                            
                        default:
                            score += dieFace * 100;
                            break;
                    }
                    break;
                case 4:
                    switch (dieFace) {
                        case 1:
                            score += 2000;
                            break;
                        default:
                            score += dieFace * 100;
                            score += (dieFace * 100);
                            break;
                    }
                    break;

                case 5:
                    switch (dieFace) {
                        case 1:
                            score += 3000;
                            break;
                        default:
                            score += dieFace * 100;
                            score += ((dieFace * 100) * 2);
                            break;
                    }
                    break;

                case 6:
                    switch (dieFace) {
                        case 1:
                            score += 4000;
                            break;
                        default:
                            score += dieFace * 100;
                            score += ((dieFace * 100) * 3);
                            break;
                    }
                    break;
            }

            }
            for (int y = 0; y < straight.length; y++) {
                if (straight[y]) {
                    straights += 1;
                }
            }



            for (int i = 0; i < twoOfAKind.length; i++) {
                if (twoOfAKind[i]) {
                    doubles += 1;
                }
            }

            if (straights == 6) {
                score = 1500;
            }
            if (doubles == 3) {
                score = 500;
            }
            return score;
    }
        
}
        

    
    



